﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using PPI.Client.Entities;
using PPIDataAccess;

namespace PPI.ServiceLogic
{
    public class LReport
    {

        public static DataSet GetReportPolesByAge(int projectId, string connectionKey)
        {
            return DReport.GetReportPolesByAge(projectId, connectionKey);
        }

        public static DataSet GetReportVisitsByTop(int projectId, string connectionKey)
        {
            return DReport.GetReportVisitsByTop(projectId, connectionKey);
        }

        public static DataSet GetReportVisitsByWeekAndContact(string connectionKey)
        {
            return DReport.GetReportVisitByWeekContact(connectionKey);
        }
        
        public static DataSet GetReportPolesByWeekAndContact(string connectionKey)
        {
            return DReport.GetReportPoleByWeekContact(connectionKey);
        }

        public static DataSet GetReportInspectionByWeekAndContact(string connectionKey)
        {
            return DReport.GetReportInspectionByWeekAndContact(connectionKey);

        }

        public static DataSet GetReportInspectionTypeByWeekAndInspector(string connectionKey)
        {
            return DReport.GetReportInspectionTypeByWeekAndInspector(connectionKey);

        }

        public static DataSet GetReportInspectionTypeByWeekAndInspector(int projectId, string connectionKey)
        {
            return DReport.GetReportInspectionTypeByWeekAndInspector(projectId, connectionKey);
        }

        public static DataSet GetReportDistributionInspectionTypeByWeekAndInspector(string connectionKey)
        {
            return DReport.GetReportDistributionInspectionTypeByWeekAndInspector(connectionKey);

        }

        public static DataSet GetReportProjectSummary(string connectionKey)
        {
            DataSet ds = new DataSet();
            DataSet dsReportSummary = DReport.GetReportProjectSummary(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[0].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary";

            dsReportSummary = DReport.GetReportProjectSummary_Issue(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[1].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary_Isssue";


            dsReportSummary = DReport.GetReportProjectSummary_Budget(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[2].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary_Budget";
        
            DataRelation relationSummaryIssue = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Isssue",
                                    new DataColumn[] {ds.Tables[0].Columns["Utility_ProjectId"]},new DataColumn[] {ds.Tables[1].Columns["ProjectId"]},false);

            DataRelation relationSummaryBudget = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Budget",
                                    new DataColumn[] {ds.Tables[0].Columns["Utility_ProjectId"]},new DataColumn[] {ds.Tables[2].Columns["ProjectId"]},false);

            ds.Relations.Add(relationSummaryIssue);
            ds.Relations.Add(relationSummaryBudget);
            return ds;
        }

        public static DataSet GetReportProjectSummary(int projectId, string connectionKey)
        {
            DataSet ds = new DataSet();
            DataSet dsReportSummary = DReport.GetReportProjectSummary(projectId, connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[0].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary";

            dsReportSummary = DReport.GetReportProjectSummary_Issue(projectId, connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[1].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary_Isssue";


            dsReportSummary = DReport.GetReportProjectSummary_Budget(projectId, connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[2].TableName = "SQL2005_390264_devpoleposiDataSet_up_Report_ProjectSummary_Budget";

            DataRelation relationSummaryIssue = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Isssue",
                                    new DataColumn[] { ds.Tables[0].Columns["Vendor_ProjectId"] }, new DataColumn[] { ds.Tables[1].Columns["ProjectId"] }, false);

            DataRelation relationSummaryBudget = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Budget",
                                    new DataColumn[] { ds.Tables[0].Columns["Vendor_ProjectId"] }, new DataColumn[] { ds.Tables[2].Columns["ProjectId"] }, false);

            ds.Relations.Add(relationSummaryIssue);
            ds.Relations.Add(relationSummaryBudget);
            return ds;
        }

        public static DataSet GetDistributionInspectionReportProjectSummary(string connectionKey)
        {
            DataSet ds = new DataSet();
            DataSet dsReportSummary = DReport.GetReportDistributionInspectionProjectSummary(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[0].TableName = "SQL2005_390264_betaDataSet_up_Report_DistributionInspectionProjectSummary";


            dsReportSummary = DReport.GetReportDistributionInspectionProjectSummary_Issue(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[1].TableName = "SQL2005_390264_betaDataSet_up_Report_DistributionInspection_ProjectSummary_Isssue";


            dsReportSummary = DReport.GetReportDistributionInspectionProjectSummary_Budget(connectionKey);
            ds.Tables.Add(dsReportSummary.Tables[0].Clone());
            ds.Merge(dsReportSummary.Tables[0]);
            ds.Tables[2].TableName = "SQL2005_390264_betaDataSet_up_Report_DistributionInspection_ProjectSummary_Budget";
            
            DataRelation relationSummaryIssue = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Isssue",
                                    new DataColumn[] { ds.Tables[0].Columns["Vendor_ProjectId"] }, new DataColumn[] { ds.Tables[1].Columns["ProjectId"] }, false);
            ds.Relations.Add(relationSummaryIssue);
            
            DataRelation relationSummaryBudget = new DataRelation("up_Report_ProjectSummary_up_Report_ProjectSummary_Budget",
                                    new DataColumn[] { ds.Tables[0].Columns["Vendor_ProjectId"] }, new DataColumn[] { ds.Tables[2].Columns["ProjectId"] }, false);
            
            ds.Relations.Add(relationSummaryBudget);

            return ds;
        }

        public static DataSet GetReportLineProblems(string connectionKey)
        {
            return DReport.GetReportLineProblems(connectionKey);

        }
        public static DataSet GetReportIssueByResult(string connectionKey)
        {
            return DReport.GetReportIssueByResult(connectionKey);
        }

        public static DataSet GetReportAssetDescription(Int32 assetId, string connectionKey)
        {
            DataSet ds = new DataSet();
            DataSet dsAsset = DReport.GetReportAssetDescription(assetId,connectionKey);
            ds.Tables.Add(dsAsset.Tables[0].Clone());
            ds.Merge(dsAsset.Tables[0]);
            ds.Tables[0].TableName = "SQL2005_390264_betaDataSet2_up_Report_InformationAsset";

            dsAsset = DReport.GetReportAssetDescriptionGPS(assetId,connectionKey);
            ds.Tables.Add(dsAsset.Tables[0].Clone());
            ds.Merge(dsAsset.Tables[0]);
            ds.Tables[1].TableName = "SQL2005_390264_betaDataSet2_up_Report_InformationAsset_Gps";


            dsAsset = DReport.GetReportAssetDescriptionInspection(assetId,connectionKey);
            ds.Tables.Add(dsAsset.Tables[0].Clone());
            ds.Merge(dsAsset.Tables[0]);
            ds.Tables[2].TableName = "SQL2005_390264_betaDataSet2_up_Report_InformationAsset_Inspections";

            DataRelation relationGPS = new DataRelation("up_Report_InformationAsset_up_Report_InformationAsset_Gps",
                                    new DataColumn[] { ds.Tables[0].Columns["Utility_Asset_XMissionStructureId"] }, new DataColumn[] { ds.Tables[1].Columns["Utility_Asset_XMissionStructureFK"] }, false);

            DataRelation relationInspection = new DataRelation("up_Report_InformationAsset_up_Report_InformationAsset_Inspections",
                                    new DataColumn[] { ds.Tables[0].Columns["Utility_Asset_XMissionStructureId"] }, new DataColumn[] { ds.Tables[2].Columns["Utility_Asset_XMissionStructureFK"] }, false);

            ds.Relations.Add(relationGPS);
            ds.Relations.Add(relationInspection);
            return ds;
        }
    }
}
